package deviseMode.create.prototype;

/*懒汉式(线程安全，同步代码块)[不可用]
但是这种同步并不能起到线程同步的作用。跟第3种实现方式遇到的情形一致，假如一个线程进入了if (singleton == null)判断语句块，
还未来得及往下执行，另一个线程也通过了这个判断语句，这时便会产生多个实例。
* */

    public class LazySynCodePiecesSingleton {

    private static LazySynCodePiecesSingleton singleton;

    private LazySynCodePiecesSingleton() {}

    public static  LazySynCodePiecesSingleton getInstance() {
        if (singleton == null) {
            synchronized (LazySynCodePiecesSingleton.class) {
                singleton = new LazySynCodePiecesSingleton();
            }
        }
        return singleton;
    }
 }
